<template>
  <div>
   <el-form
      :model="formData"
      inline
      style="display: flex; justify-content: flex-end; margin-top: 10px"
    >
      <el-form-item prop="userId">
        <el-input
          v-model="formData.userId"
          placeholder="请输入用户id"
        ></el-input>
      </el-form-item>

      <el-form-item prop="keyword">
        <el-input
          v-model="formData.keyword"
          placeholder="请输入关键字"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="getHistory" type="primary" icon="el-icon-search">查找</el-button>
      </el-form-item>
    </el-form>


    
    <el-table v-loading='HistoryLoading' :data="HistoryData" border>
      <el-table-column align="center" label="搜索id" prop="id"></el-table-column>
      <el-table-column align="center" label="用户id" prop="userId"></el-table-column>
      <el-table-column align="center" label="关键字" prop="keyword"></el-table-column>
      <el-table-column align="center" label="添加时间" prop="addTime"></el-table-column>
    </el-table>

     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[1, 20, 30, 50, 100]"
      :page-size="pageInfo.limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
  </div>
</template>
  
<script>
import axios from 'axios'
export default {
  name: 'searchHistory',
  componentTitle: '搜索历史',
  data () {
    return {
      HistoryLoading:false,
      pageInfo:{
        page:1,
        limit:10,
        total:0
      },
      HistoryData:[],
      formData:{
         userId:'',
          keyword:''
      }
    }
  },
  mounted(){
    this.getHistory()
  },
  methods:{
    getHistory(){ 
      this.HistoryLoading=true
      axios({
        url: 'http://192.168.200.251:8888/admin/history/list',
        method:'get',
        params:{
          page:this.pageInfo.page,
          limit:this.pageInfo.limit,
         ...this.formData
        },
          headers: {
          "shopping-admin-token": sessionStorage.getItem(
            "shopping-admin-token"
          ),
          }
      }).then(res=>{
        this.HistoryLoading=false
        this.HistoryData=res.data.data.list
        this.pageInfo.total=res.data.data.total
      })

    },
    handleSizeChange(value){
      this.pageInfo.limit=value
      this.getHistory()
    },
    handleCurrentChange(value){
      this.pageInfo.page=value
      this.getHistory()
    }
  }
}
</script>

